<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增展会名单')" />
</head>
<body>
<div class="main-content">
    <form id="form-eventRoster-add" class="form-horizontal">
        <input name="deptId" type="hidden" id="treeId"/>
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">展会名称：</label>
                    <div class="col-sm-8">
                        <input name="eventName" placeholder="请输入展会名称" class="form-control" type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">展会分类：</label>
                    <div class="col-sm-8">
                        <select id="sortId" name="sortId" class="form-control m-b">
                            <option th:each="post:${eventSort}" th:value="${post.sortId}" th:text="${post.sortName}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">展会时间：</label>
                    <div class="col-xs-10">
                        <input type="text" class="time-input" id="startTime" placeholder="开始时间" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss" name="params[beginTime]"/>
                        <span>-</span>
                        <input type="text" class="time-input" id="endTime" placeholder="结束时间" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss" name="params[endTime]"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">展会简介：</label>
                    <div class="col-xs-10">
                        <textarea id="eventProfiles" name="eventProfiles" maxlength="500" class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">展会地址：</label>
                    <div class="col-xs-10">
                        <textarea id="eventAddress" name="eventAddress" maxlength="500" class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>

    </form>
</div>

<th:block th:include="include :: footer" />
<script>
    var prefix = ctx + "system/eventRoster";

    $("#form-eventRoster-add").validate({
        onkeyup: false,
        rules:{
            eventName:{
                minlength: 2,
                maxlength: 20,
                remote: {
                    url: prefix + "/checkEventNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "eventName": function() {
                            return $.common.trim($("#eventName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "eventName": {
                remote: "展会名称已经存在"
            }
        },
        focusCleanup: true
    });

    $('input').on('ifChanged', function(obj){
        var type = $(this).val();
        var checked = obj.currentTarget.checked;
        if (type == 1) {
            if (checked) {
                $._tree.expandAll(true);
            } else {
                $._tree.expandAll(false);
            }
        } else if (type == "2") {
            if (checked) {
                $._tree.checkAllNodes(true);
            } else {
                $._tree.checkAllNodes(false);
            }
        } else if (type == "3") {
            if (checked) {
                $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
            } else {
                $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
            }
        }
    })

    function submitHandler() {
        if ($.validate.form()) {
            add();
        }
    }

    function add() {
        // var myselect=document.getElementById("sortId");
        var sortId = document.getElementById("sortId").value;
        var eventName = $("input[name='eventName']").val();
        var eventProfiles = document.getElementById("eventProfiles").value;
        var eventAddress = document.getElementById("eventAddress").value;
        var startTime = document.getElementById("startTime").value;
        var endTime = document.getElementById("endTime").value;
        $.ajax({
            cache : true,
            type : "POST",
            url : prefix + "/add",
            data : {
                "eventName": eventName,
                "sortId": sortId,
                "eventProfiles": eventProfiles,
                "eventAddress": eventAddress,
                "startTime": startTime,
                "endTime": endTime
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }

    // function submitHandler() {
    //     var chrtype = [[${#strings.defaultString(@config.getKey('sys.account.chrtype'), 0)}]];
    //     var password = $("#password").val();
    //     if ($.validate.form() && checkpwd(chrtype, password)) {
    //         var data = $("#form-eventRoster-add").serializeArray();
    //         var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
    //         var roleIds = $.form.selectCheckeds("role");
    //         var postIds = $.form.selectSelects("post");
    //         data.push({"name": "status", "value": status});
    //         data.push({"name": "roleIds", "value": roleIds});
    //         data.push({"name": "postIds", "value": postIds});
    //         $.operate.saveTab(prefix + "/add", data);
    //     }
    // }

</script>
</body>
</html>